# Copyright 2012 Tobias Marschall
# 
# This file is part of CLEVER.
# 
# CLEVER is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# CLEVER is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with CLEVER.  If not, see <http://www.gnu.org/licenses/>.


add_library( CleverLib SHARED
	AlignmentPair.cpp
	ASTagCalculator.cpp
	BamHelper.cpp
	CoverageMonitor.cpp
	CoverageWriter.cpp
	DefaultGapCostDistributions.cpp
	Distributions.cpp
	FastqReader.cpp
	GenotypeDistribution.cpp
	Genotyper.cpp
	GroupWiseBamReader.cpp
	HistogramBasedDistribution.cpp
	Histogram.cpp
	IndelLengthDistribution.cpp
	LengthAwareVariationIndex.cpp
	MismatchWeightTrack.cpp
	NamedDnaSequence.cpp
	OverlappingRegions.cpp
	PackedAlignmentPair.cpp
	PositionSet.cpp
	ReadGroups.cpp
	ShortDnaSequence.cpp
	SingleTrackCoverageMonitor.cpp
	SortedBamReader.cpp
	SumOfBinomials.cpp
	VariationCaller.cpp
	Variation.cpp
	VariationIndex.cpp
	VariationListParser.cpp
	VariationUtils.cpp
	VersionInfo.cpp
)
set_target_properties( CleverLib PROPERTIES SOVERSION "2.0.0" OUTPUT_NAME "clever" )

add_executable ( bam-to-alignment-priors
	bam-to-alignment-priors.cpp
)

add_executable (clever-core
	clever-core.cpp
	CliqueFinder.cpp
	Clique.cpp
	GaussianEdgeCalculator.cpp
	CliqueWriter.cpp
	EdgeWriter.cpp
	AnyDistributionEdgeCalculator.cpp
	ReadSetZTester.cpp
	ReadSetGenericTester.cpp
	ReadGroupAwareEdgeCalculator.cpp
	ReadSetGroupWiseZTester.cpp
)

add_executable (insert-length-histogram
	insert-length-histogram.cpp
)

add_executable ( add-score-tags-to-bam
	add-score-tags-to-bam.cpp
)

add_executable (split-reads
	split-reads.cpp
)

add_executable (laser-core
	laser-core.cpp
	SplitAligner.cpp
	split/SplitMapping.cpp
	split/WholeMapping.cpp
	split/InterSplitMapping.cpp
	split/Read.cpp
)

add_executable (bam2fastq
	bam2fastq.cpp
)

add_executable (remove-redundant-variations
	remove-redundant-variations.cpp
)

add_executable ( precompute-distributions
	precompute-distributions.cpp
	ReadSetGenericTester.cpp
)

add_executable ( laser-recalibrate
	laser-recalibrate.cpp
)

add_executable ( extract-bad-reads
	extract-bad-reads.cpp
)

add_executable (filter-variations
	filter-variations.cpp
)

add_executable (merge-to-vcf
	merge-to-vcf.cpp
)

add_executable (multiline-to-xa
	multiline-to-xa.cpp
)

add_executable (filter-bam
	filter-bam.cpp
)

add_executable (genotyper
	genotyper-tool.cpp
)

add_executable (read-group-stats
	read-group-stats.cpp
)

add_executable (merge-putative-variations
	merge-putative-variations
)

add_executable (ctk-version
	ctk-version.cpp
)

target_link_libraries(bam-to-alignment-priors CleverLib ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries(clever-core CleverLib)
target_link_libraries(insert-length-histogram CleverLib)
target_link_libraries(add-score-tags-to-bam CleverLib ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries(split-reads CleverLib ${ZLIB_LIBRARY})
target_link_libraries(laser-core CleverLib ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries(bam2fastq CleverLib)
target_link_libraries(remove-redundant-variations CleverLib ${ZLIB_LIBRARY})
target_link_libraries(precompute-distributions CleverLib)
target_link_libraries(laser-recalibrate CleverLib)
target_link_libraries(extract-bad-reads CleverLib ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries(filter-variations CleverLib)
target_link_libraries(merge-to-vcf CleverLib)
target_link_libraries(multiline-to-xa CleverLib)
target_link_libraries(filter-bam CleverLib)
target_link_libraries(genotyper CleverLib)
target_link_libraries(read-group-stats CleverLib)
target_link_libraries(merge-putative-variations CleverLib)
target_link_libraries(ctk-version CleverLib)

target_link_libraries(CleverLib ${Boost_LIBRARIES} BamTools)
set(ALL_EXE_TARGETS 
	bam-to-alignment-priors
	insert-length-histogram
	clever-core
	add-score-tags-to-bam
	split-reads
	laser-core
	bam2fastq
	remove-redundant-variations
	precompute-distributions
	laser-recalibrate
	extract-bad-reads
	filter-variations
	merge-to-vcf
	multiline-to-xa
	filter-bam
	genotyper
	read-group-stats
	merge-putative-variations
	ctk-version
)
set(ALL_LIB_TARGETS CleverLib)

add_custom_target(Version ALL COMMAND ${CMAKE_COMMAND} -D SRCDIR=${CMAKE_SOURCE_DIR} -D DSTDIR=${CMAKE_BINARY_DIR} -P ${CMAKE_CURRENT_SOURCE_DIR}/get-version.cmake)
# add_custom_target(DeleteVersionFile ALL DEPENDS ${ALL_EXE_TARGETS} ${ALL_LIB_TARGETS} COMMAND ${CMAKE_COMMAND} -E remove version.h)
foreach(f ${ALL_EXE_TARGETS} ${ALL_LIB_TARGETS})
	add_dependencies(${f} Version)
endforeach()

install(TARGETS ${ALL_EXE_TARGETS} RUNTIME DESTINATION bin)
install(TARGETS ${ALL_LIB_TARGETS} LIBRARY DESTINATION "lib" ARCHIVE DESTINATION "lib")
